package org.example.servlet_01;

import java.io.*;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

/*
   通过WebServlet注解配置
 */

/**
 * Servlet路径配置
 * 1.@WebServlet({"/d1", "/d2", "/d3", "/d4"})
 * 2.@WebServlet("/d1/dd1")
 * 3.@WebServlet("/d1/*")
 * 4.@WebServlet("*.str")
 */

@WebServlet({"/helloServlet","/hi"})
public class HelloServlet extends HttpServlet {
    private String message;
    @Override
    public void init() {
        System.out.println("我是注解配置的Servlet，很高级噢");
        message = "welcome to my servlet ！";
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");
        System.out.println(request.getRequestURI());
        // Hello
        PrintWriter out = response.getWriter();
        out.println("<html><body>");
        out.println("<h1>" + message + "</h1>");
        out.println("</body></html>");
    }

    public void destroy() {
    }
}